package com.yibo.feign;

import com.yibo.support.jwt.JWTUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class AuthTokenScheduledTask {

    private JWTUtils jwtUtils = JWTUtils.getInstance();

    public static final String  YIBO_AUTH_TOKEN = "yibo_auth_token";

    /**
     * 定时更新系统内部调用token 24小时刷新一次，延迟一秒
     */
    @Scheduled(fixedDelay = 1000 * 60 * 60 * 24,initialDelay = 1000)
    public void reloadApiToken(){

        String token = jwtUtils.getToken("yibo");

        //设置到系统system中
        System.setProperty(YIBO_AUTH_TOKEN,token);
    }


}
